<template>
<div class="wrapper">
    <swiper :options="swiperOption" ref="mySwiper" someSwiperEvent="callback" v-if="showSwiper">
      <swiper-slide v-for="item in list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="轮播图片">
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
      <!-- <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div> -->
      <!-- <div class="swiper-scrollbar" slot="scrollbar"></div> -->
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 2000
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
// 穿透符'>>>' 不受scoped限制
  .wrapper >>> .swiper-pagination-bullet-active
    background-color #fff
  .wrapper
    // 31.25 = 图片height/width 200/640
      // height 31.25%vw
    overflow hidden
    height 0
    width 100%
    // 图片高宽比例自适应 把高为0 用 padding-bottom等于父组件的宽度*比例
    padding-bottom 31.25%
    background-color #eee
    .swiper-img
      width 100%
</style>
